<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {
      margin: 0;
      padding: 0;
      border: 0;
      box-sizing: border-box;
    }

    a {
      text-decoration: none;
      color: #000;
      display: block;
      width: 100%;
    }

    h3 {
      text-align: center;
      height: 60px;
      line-height: 60px;
      background-color: rgb(212, 12, 12);
      color: #fff;
    }

    ul {
      list-style: none;
    }

    li {
      padding: 10px 15px;
      border-bottom: 1px solid #ccc;
      display: flex;
      justify-content: space-between;
      align-items: center;
    }

    button {
      width: 25px;
      height: 25px;
      background-color: rgb(212, 12, 12);
      color: #fff;
      border-radius: 3px;
    }

    button:active {
      background-color: rgb(156, 15, 15);
    }


    .btn {
      padding: 5px 10px;
      width: fit-content;
      height: 35px;
      color: #fff;
      background-color: rgb(212, 12, 12);
      margin-left: 20px;
    }

    .btn:active {
      background-color: rgb(179, 25, 25);
    }

    .bottom-box {
      padding: 15px 20px;
      position: fixed;
      width: 100%;
      bottom: 0;
    }

    .flex-end {
      display: flex;
      justify-content: flex-end;
      align-items: center;
    }
  </style>
</head>

<body>
  <h3>我的购物车</h3>
  <ul id="list">
    <li data-id="">
      <div>
        <span data-name="">商品</span>
        <span data-price="">1823</span>
      </div>
      <div>
        <button data-cut="">-</button>
        <span data-num="">1</span>
        <button data-add="">+</button>
      </div>
    </li>
  </ul>

  <div class="bottom-box flex-end">
    <div>合计金额: <span>9999</span> </div>
    <button class="btn">去支付</button>
  </div>

  <script src="http://localhost:7001/package/axios.min.js"></script>
  <script src="http://localhost:7001/js/axios.js"></script><!-- 拦截器 -->
  <script>
    ; (async function () {
      const res = await axios({
        method: 'get',
        url: `/api/cartList`,
      })

      console.log('-----', res);


      list.innerHTML = res.data.map(item => {
        return `
        <li data-id="${item.id}">
          <div>
            <span data-name="${item.id}">${item.name}</span>
            <span data-price="${item.id}">${item.price}</span>
          </div>
          <div>
            <button data-cut="${item.id}">-</button>
            <span data-num="${item.id}">${item.num}</span>
            <button data-add="${item.id}">+</button>
          </div>
        </li>
        `
      }).join('')
    })()
  </script>
</body>

</html>